// 谷歌推出的设计风格
import 'package:flutter/material.dart';
// ios的风格
import 'package:flutter/cupertino.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:provide/provide.dart';
import './provide/current_index.dart';
import './category_page.dart';
import './home_page.dart';
import './cart_page.dart';
import './member_page.dart';



// class IndexPage extends StatefulWidget {
//   IndexPage({Key key}) : super(key: key);

//   _IndexPageState createState() => _IndexPageState();
// }

class IndexPage extends StatelessWidget {
  final List<BottomNavigationBarItem> bottomTabs = [
    BottomNavigationBarItem(
      icon:Icon(CupertinoIcons.home),
      title: Text('首页')
     ),
     BottomNavigationBarItem(
      icon:Icon(CupertinoIcons.home),
      title: Text('分类')
     ),
     BottomNavigationBarItem(
      icon:Icon(CupertinoIcons.shopping_cart),
      title: Text('购物车')
     ),
     BottomNavigationBarItem(
      icon:Icon(CupertinoIcons.home),
      title: Text('会员中心')
     )
  ];
    final List<Widget>  tabBodies = [
      HomePage(),
      CategoryPage(),
      CartPage(),
      MemberPage(),
  ];
  @override
  Widget build(BuildContext context) {
    ScreenUtil.instance = ScreenUtil(width: 750,height: 1334)..init(context);
    return Provide<CurrentIndexProvide>(
      builder: (context,child,val){
          int currentIndex= Provide.value<CurrentIndexProvide>(context).currentIndex;
          return Scaffold(
            backgroundColor: Color.fromRGBO(244, 245, 245, 1.0),
            bottomNavigationBar: BottomNavigationBar(
              type: BottomNavigationBarType.fixed,
              // 显示的是那个页面
              currentIndex: currentIndex,
              items:bottomTabs,
              onTap:(index){
                Provide.value<CurrentIndexProvide>(context).changeIndex(index);
              },
            ),
            body:IndexedStack(
              index:currentIndex ,
              children: tabBodies,
            ),
        );
      },
    );
  }
}






// class _IndexPageState extends State<IndexPage> {
//   final List<BottomNavigationBarItem> bottomTabs = [
//     BottomNavigationBarItem(
//       icon:Icon(CupertinoIcons.home),
//       title: Text('首页')
//      ),
//      BottomNavigationBarItem(
//       icon:Icon(CupertinoIcons.home),
//       title: Text('分类')
//      ),
//      BottomNavigationBarItem(
//       icon:Icon(CupertinoIcons.shopping_cart),
//       title: Text('购物车')
//      ),
//      BottomNavigationBarItem(
//       icon:Icon(CupertinoIcons.home),
//       title: Text('会员中心')
//      )
//   ];
  
//   final List<Widget>  tabBodies = [
//     HomePage(),
//     CategoryPage(),
//     CartPage(),
//     MemberPage(),
//   ];
//   int currentIndex = 0;
//   var currentPage;

//   @override
//   void initState() {
//     currentPage = tabBodies[currentIndex];
//     super.initState();
//   } 


//   @override
//   Widget build(BuildContext context) {
//      ScreenUtil.instance = ScreenUtil(width: 750,height: 1334)..init(context);
//     // 屏幕适配
//     // print('设备的像素密度：${ScreenUtil.pixelRatio}');
//     // print('设备的高：${ScreenUtil.screenHeight}');
//     // print('设备的高：${ScreenUtil.screenWidth}');
//     return Scaffold(
//       backgroundColor: Color.fromRGBO(244, 245, 245, 1.0),
//       bottomNavigationBar: BottomNavigationBar(
//         type: BottomNavigationBarType.fixed,
//         // 显示的是那个页面
//         currentIndex: currentIndex,
//         items:bottomTabs,
//         onTap:(index){
//           setState(() {
//             currentIndex = index;
//             currentPage = tabBodies[index];
//           });
//         },
//       ),
//       body:IndexedStack(
//         index:currentIndex ,
//         children: tabBodies,
//       ),
//     );
//   }
// }